var num = Number(location.search.slice(1))

$.ajax({
    type: "post",
    url: "../php/id.php",
    data: {
        id: num
    },
    dataType: "json",
    success: function (res) {
        var { status, list } = res;
        if (status) {
            var html = "";
            list.forEach(({ title, img, oldmoney, money, id }) => {
                html += `<h1>${title}</h1>
            <div>
                <div class="left">
                    <div class="preview-wapper">
                        <div class="preview">
                            <img class="smallImg" src="${img}" alt="">
                            <div class="shadow"></div>
                        </div>
                        <div class="preview-scale">
                            <img class="bigImg" src="${img}" alt="">
                        </div>
                    </div>
                    <div class="preview-info">
                    </div>
                </div>
                <div class="right">
                    <p><s>￥${oldmoney}</s>
                        <span>￥${money}.00</span>
                    </p>
                    <a href="javascript:;" class="jiaru">加入购物车</a>
                </div>
            </div>`;
                $(".centent").html(html);
                $(".right").on("click", ".jiaru", function () {
                    var lgc = getCookie("lgc");
                    if (!lgc) {
                        alert("请先登录")
                        location.href = "./index.html"
                    } else {
                        $.ajax({
                            type: "post",
                            url: "../php/jia.php",
                            data: { user: lgc, g_id: num, number: 1 },
                            dataType: "json",
                            success: function (result) {
                                var { status, message } = result;
                                if (status) {
                                    isUserOk = true;
                                } else {
                                    throw message
                                }
                            }
                        })
                        location.href = "./shoping.html"
                    }
                })
            })
        }
    }
})


